import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/model/week_food_model.dart';
import 'package:saas_order_meal/res/resources.dart';

import '../net/net_response/order_detail_data.dart';
import '../saas_order_meal.dart';

class HasOrderedDetailViewModel extends BaseViewModel{
  HasOrderedDetailViewModel(BuildContext? context,{required this.detail}) : super(context);

  final  OrderDetailData detail;

  var model = WeekFoodModel();


  @override
  void onCreated() {
    super.onCreated();
  }

  void cancelClick(){
    showCupertinoDialog(context: context, builder: (context){
      return CupertinoAlertDialog(
        content: Text("确定要取消该订单吗"),
        actions: [
          TextButton(onPressed: (){
            Go().pop();
          }, child: CommonText('取消',textColor: Colors.grey)),
          TextButton(onPressed: (){
            Go().pop();
            cancel();
          }, child: CommonText('确定',textColor: SaasOrderMeal.mainColor)),
        ],
      );
    });
  }

  Future<void> cancel() async {
    showLoadingDialog(msg: '提交中。。。');
    try{
      await model.cancelFood(detail.id);
      hideDialog();
      Go().pop(result: "1");
    }catch(e){
      showToast(e.toNetError());
      hideDialog();
    }
  }
}